package top.codedance.iotp.server.net.session;

import top.codedance.iotp.common.util.AsymmetricEncryption;
import cd.io.netty.channel.Channel;
import top.codedance.iotp.server.ServerApplication;
import org.apache.log4j.Logger;

public class Session {
    private Logger logger = ServerApplication.getLogger(Session.class);

    private String deviceId;
    private Channel channel;
    private AsymmetricEncryption.KeyStringPair keyStringPair;
    private String clientPublicKey;

    public Session(){
        genKeys();
    }

    public Session(String clientPublicKey) {
        this.clientPublicKey = clientPublicKey;
        genKeys();
    }

    public Session(Channel channel) {
        this.channel = channel;
    }

    public Session(String deviceId, Channel channel) {
        this.deviceId = deviceId;
        this.channel = channel;
        genKeys();
    }

    public void genKeys(){
        try {
            this.keyStringPair = AsymmetricEncryption.genKeyPair();
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public Channel getChannel() {
        return channel;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    public AsymmetricEncryption.KeyStringPair getKeyStringPair() {
        return keyStringPair;
    }

    public String getClientPublicKey() {
        return clientPublicKey;
    }

    public void setClientPublicKey(String clientPublicKey) {
        this.clientPublicKey = clientPublicKey;
    }
}
